package pso.velocity;

import evolution.stop.IterationStopCondition;
import pso.PSOAlgorithm;

public class LinearlyDecreasingInertiaWeightVelocityUpdateStrategy extends
		AbstractInertiaWeightVelocityUpdateStrategy {

	// private double beginInertia;
	private double endInertia;
	private PSOAlgorithm psoAlgorithm;
	private double inertiaDiff;
	private int maxIteration;

	public LinearlyDecreasingInertiaWeightVelocityUpdateStrategy(
			PSOAlgorithm pso, double beginInertia, double endInertia) {
		this.psoAlgorithm = pso;
		// this.beginInertia = beginInertia;
		this.endInertia = endInertia;
		inertiaDiff = beginInertia - endInertia;
		maxIteration = ((IterationStopCondition) psoAlgorithm
				.getStopCondition()).getParameter();
	}

	@Override
	public double getInertiaWeight() {
		int currentIteration = psoAlgorithm.getCurrentIteration();
		double inertia = inertiaDiff * (1 - 1.0 * currentIteration / maxIteration)
				+ endInertia;
		return inertia;
	}
}
